package com.coocaa.ops.plus.dashboard.v1.codegen.model;

import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author : bijiahao
 * @date : 2019/4/19.
 * @description: 每一表的配置
 */
@Data
public class TableInfoModel {
    private String tableName;
    private String comment;

    /**
     * 菜单elid
     */
    private String elid;
    /**
     * 请求url
     */
    private String requestUrl;

    /**
     * 指定生成的主键的ID类型
     */
    private String idType;

    private List<TableConfigInfo> tableConfigList;

    /**
     * 需要代码生成的
     */
    private List<ColumnConfigModel> columnList;
    /**
     * 父类存在，但此表不存在，需要排除的
     */
    private List<ColumnConfigModel> notExistColumnList;

    private List<String> importPackages = new ArrayList<>();


    private String baseColumnsStr;

    public String getBaseColumnsStr() {
        if (StringUtils.isEmpty(baseColumnsStr)) {
            StringBuilder names = new StringBuilder();
            int i = 0;
            int size = columnList.size();
            for (; i < size; i++) {
                ColumnConfigModel columnConfig = columnList.get(i);
                if (i == columnList.size() - 1) {
                    names.append("a." + columnConfig.getColumnName());
                } else {
                    names.append("a." + columnConfig.getColumnName()).append(", ");
                }
            }
            baseColumnsStr = names.toString();
        }
        return baseColumnsStr;
    }

}
